using System;
using System.Text;
using System.Collections;
using System.Collections.Generic;

namespace RF_Jammer_Base
{   
    public class Jammer
    {
        public const double TARGET_MAX_X = 1000; // meters
        public const double TARGET_MAX_Y = 1000; // meters
        public const double TARGET_MAX_POWER = 5;

        public const double SOURCE_MAX_X = 1000; // meters
        public const double SOURCE_MAX_Y = 1000; // meters
        public const double SOURCE_MAX_POWER = 100;

        public const int NUM_SOURCES = 10;
        public const int NUM_TARGETS = 3;

        public const int DEBUG = 0;
        public const int WARNING = 1;
        public const int NOTICE = 2;
        public const int ERROR = 3;

        ArrayList Particles;
        private int NumParticles;

        public enum JammerEvent
        {
            GO = 0
        }

        public Jammer(int NumParticles)
        {
            DebugOut("Creating New Jammer", NOTICE);
            this.NumParticles = NumParticles;
            this.Particles = new ArrayList();

            ArrayList targetNodes = new ArrayList();
            ArrayList sourceNodes = new ArrayList();

            Random rand = new Random();

            double freq = 100E6;

            int NumTargets = NUM_TARGETS;
            int NumSources = NUM_SOURCES;

            DebugOut("Creating " + NumTargets + " Target Nodes", NOTICE);
            for (int i = 0; i < NumTargets; i++)
            {
                double xcord = rand.NextDouble() * TARGET_MAX_X;
                double ycord = rand.NextDouble() * TARGET_MAX_Y;
                double power = rand.NextDouble() * TARGET_MAX_POWER;
                TargetNode tNode = new TargetNode(i, xcord, ycord, power, freq);
                targetNodes.Add(tNode);                
            }

            DebugOut("Creating " + NumSources + " Source Nodes", NOTICE);
            for (int i = 0; i < NumSources; i++)
            {
                double xcord = rand.NextDouble() * SOURCE_MAX_X;
                double ycord = rand.NextDouble() * SOURCE_MAX_Y;
                double power = rand.NextDouble() * SOURCE_MAX_POWER;
                SourceNode sNode = new SourceNode(i, xcord, ycord, power, freq);
                sourceNodes.Add(sNode);
            }

            DebugOut("Creating " + NumParticles + " Initial Particles", NOTICE);
            for (int x = 0; x < NumParticles; x++)
            {
                Particle newParticle = new Particle(x, targetNodes, sourceNodes);
                Particles.Add(newParticle);
            }
            DebugOut("New Jammer Creation Complete", NOTICE);
        }

        public void EventHandler(JammerEvent evt)
        {
        }

        static void Main(string[] args)
        {
            Jammer j = new Jammer(40);

            JammerGUI jgui = new JammerGUI(j);

            jgui.Show();

            string str = "hello";
            jgui.test(str,0);

            Console.Read();
        }

        public static void DebugOut(string str, int level)
        {
            Console.Out.WriteLine(str);
        }    
    }
}
